package cocurrency.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * Created by luzl on 4/6/2017.
 */
public class CountDownLatchTest {

    public  static void main(String[] args){

        CountDownLatch prepareLatch=new CountDownLatch(10);
        CountDownLatch startLatch=new CountDownLatch(1);
        CountDownLatch completeLatch=new CountDownLatch(10);

        for(int i=0;i<10;i++){
            CountDownLatchThread countDownLatchThread=new CountDownLatchThread(prepareLatch, startLatch,completeLatch,"First Batch Seq"+i);
            countDownLatchThread.start();
        }

        try {
            prepareLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        startLatch.countDown();
        System.out.println("Command: Let's go!");

        System.out.println("Waiting all to complete ...");
        try {
            completeLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("All thread is done ...");
    }
}
